# I'm enough of a fogey I still like make for small hacks.
# the hack isn't so small anymore, but this is working ok.
# This handles class dependencies poorly, but so does everything
# else SFAIK.

# This works on Mac and Linux; haven't attempted anything else.

SRC:=$(wildcard src/*.scala)
METASRC:=$(wildcard metasrc/*.scala)
BUILTSRC:=$(patsubst metasrc/%.scala,builtsrc/Built%.scala,${METASRC})

LIBS:=$(wildcard lib/*.jar lib/*.zip)

# ancient and glorious space removal hack
empty:=
space:= $(empty) $(empty)

# same for now
COMPILE_CP:=$(subst $(space),:,classes $(LIBS))
RUN_CP:=$(subst $(space),:,classes $(LIBS))

#CHECK:= -unchecked 
CHECK:= 
SCALAC=JAVA_OPTS="-Xmx1700M -Xms256M -Xss16M" /usr/local/bin/scalac ${CHECK} -d classes -target:jvm-1.5 -deprecation  -cp ${COMPILE_CP}
SCALA=JAVA_OPTS="-Xmx1700M  -Xms1700M -Xss16M" /usr/local/bin/scala -classpath ${RUN_CP}
GENERATE=JAVA_OPTS="-Xmx512M  -Xms512M -Xss16M" /usr/local/bin/scala -savecompiled -classpath ${COMPILE_CP}

compile: stamp

${BUILTSRC}: builtsrc/Built%.scala : metasrc/%.scala
	mkdir -p builtsrc
	${GENERATE} $< > $@

stamp:  ${SRC} ${BUILTSRC}
	mkdir -p classes
	${SCALAC} $?
	touch stamp

clean: 
	rm -rf classes
	rm -rf builtsrc
	rm -f stamp 
	rm -f deque.jar

test: stamp
	${SCALA} org.thewares.collection.test.TestDeck

littletest: stamp
	${SCALA} org.thewares.collection.test.TestLittleDeque

iteratortest: stamp
	${SCALA} org.thewares.collection.test.TestIterator

deque.jar: stamp
	cd classes; jar cvf ../deque.jar org/thewares/collection/*class org/thewares/collection/finger/*class